<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myStrategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/common.js"></script>
    <script src="../js/checkLogin.js"></script>
    <script>
        $(function () {
            var strategyId = getParams().id;
            var starNum;//星星数11
            var imgurls;//图片地址
            var tags = [];//标签数组
            //实现星星点击效果
            //绑定所有星星的点击事件
            $(".star i").click(function () {
                //清空样式
                $(".star i").removeClass("fa-star");
                $(".star i").addClass("fa-star-o");
                starNum = $(this).data("num");
                for (var i = 0; i < starNum; i++) {
                    $($(".star i")[i]).removeClass("fa-star-o");
                    $($(".star i")[i]).addClass("fa-star");
                }
            })
            var $uploadImg;//上传图片被几点的对象
            //绑定上传图片事件
            $(".imgs .rect").click(function () {
                $uploadImg = $(this);
                $("#file").click();
            })
            //读取图片上传事件来发送请求
            $("#file").change(function (data) {
                //如果有值就提交表单
                if ($(this).val()) {
                    $("#images").ajaxSubmit({
                        url: baseUrl + "images",
                        success: function (data) {
                            if (data.status) {
                                //回显上传的图片
                                $uploadImg.html("<img src='" + data.url + "' width='100%'/>");

                            }

                        }
                    })
                }

            });

            //绑定提交事件
            $("#submitBtn").click(function () {
                var systemTags = $(".tag .active input");//所有已选的系统标签
                $.each(systemTags, function (index, ele) {
                    tags.push($(ele).val());//遍历系统标签加入tag数组
                });
                var inputTags = $("#myTags").val().split(" ");//手动输入的标签
                //遍历数组获取手动标签
                $.each(inputTags, function (index, ele) {
                    if (ele) {
                        tags.push(ele);
                    }
                });


                var imgs = $(".imgs img");//所有图片上传标签
                //遍历获取图片地址
                var temp = ''
                $.each(imgs, function (index, ele) {
                    if (ele) {
                        temp += $(ele).attr("src") + ";";
                    }
                });
                imgurls = temp;
                var json = {
                    starNum: starNum,
                    content: $("textarea[name=content]").val(),
                    imgUrls: imgurls,
                    tags: tags
                };
                $.post(baseUrl + "strategies/" + strategyId + "/comments", json, function (data) {
                    //保存成功跳回上一页时
                    window.window.history.go(-1);
                })
            })

        })
    </script>
</head>
<body>

<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>

        </div>
        <div class="col">
            <span>点评</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="comment">
    <div class="container star">
        <p>你对该旅游地的评价</p>
        <i class="fa fa-star-o fa-lg" data-num="1"></i>
        <i class="fa fa-star-o fa-lg" data-num="2"></i>
        <i class="fa fa-star-o fa-lg" data-num="3"></i>
        <i class="fa fa-star-o fa-lg" data-num="4"></i>
        <i class="fa fa-star-o fa-lg" data-num="5"></i>
    </div>
    <hr/>
    <div class="container tag">
        <p>请为该旅游地选择合适的标签（大家都在评）</p>
        <div class="btn-group-toggle" data-toggle="buttons">
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="价格便宜"> 价格便宜
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="住宿方便"> 住宿方便
            </label>
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="旅游景点多"> 旅游景点多
            </label>
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="适合拍照">适合拍照
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="吃的很多">吃的很多
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="交通不方便">交通不方便
            </label>
        </div>

        <p>添加你自己的标签</p>
        <input id="myTags" class="form-control" placeholder="请使用空格隔开标签，每个标签不超8个字"/>

        <p>更多评价内容</p>
        <textarea name="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
    </div>
    <!--更换封面的隐藏上传标签-->
    <form id="images" enctype="multipart/form-data" method="post">
        <input type="file" name="file" hidden id="file">
    </form>
    <div class="container imgs ">
        <p>上传图片</p>

        <div class="row">
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
        </div>
    </div>

</div>


<div class="operation">
    <button class="btn" onclick="window.history.go(-1)">放弃评价</button>
    <button class="btn" id="submitBtn">提交评价</button>
</div>


</body>


</html>